

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>scitools.easyviz.vtk_new_ &mdash; SciTools 0.9.0 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '0.9.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="SciTools 0.9.0 documentation" href="../../../index.html" />
    <link rel="up" title="Module code" href="../../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for scitools.easyviz.vtk_new_</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This is a template file for writing new backends. It is a fully functional</span>
<span class="sd">backend, but no output is produced. One can specify this backend by</span>

<span class="sd">  python somefile.py --SCITOOLS_easyviz_backend template</span>

<span class="sd">or one can specify the backend in the SciTools configuration file</span>
<span class="sd">scitools.cfg under the [easyviz] section</span>

<span class="sd">  [easyviz]</span>
<span class="sd">  backend = template</span>

<span class="sd">and then</span>

<span class="sd">  from scitools.std import *</span>

<span class="sd">or if just easyviz is needed</span>

<span class="sd">  from scitools.easyviz import *</span>

<span class="sd">When writing a new backend, one can copy this file to xxx_.py (note the</span>
<span class="sd">underscore), where &#39;xxx&#39; is the name of the new backend. Then replace all</span>
<span class="sd">instances of &#39;template&#39; with &#39;xxx&#39; and start implementing the class</span>
<span class="sd">methods below. The most important methods are figure, _replot, and hardcopy.</span>

<span class="sd">REQUIREMENTS:</span>

<span class="sd">VTK &gt;= 4.2</span>
<span class="sd">Python bindings for VTK.</span>

<span class="sd">Notes:</span>

<span class="sd">- filled contours (contourf) doesn&#39;t look good in VTK 5.0.</span>

<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">division</span>

<span class="kn">from</span> <span class="nn">common</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">scitools.globaldata</span> <span class="kn">import</span> <span class="n">DEBUG</span><span class="p">,</span> <span class="n">VERBOSE</span><span class="p">,</span> <span class="n">OPTIMIZATION</span>
<span class="kn">from</span> <span class="nn">scitools.misc</span> <span class="kn">import</span> <span class="n">test_if_module_exists</span> 
<span class="kn">from</span> <span class="nn">scitools.numpyutils</span> <span class="kn">import</span> <span class="n">allclose</span>
<span class="kn">from</span> <span class="nn">misc</span> <span class="kn">import</span> <span class="n">_update_from_config_file</span>

<span class="n">test_if_module_exists</span><span class="p">(</span><span class="s">&#39;vtk&#39;</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">&#39;You need to install the vtk package.&#39;</span><span class="p">,</span> <span class="n">abort</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">vtk</span>
<span class="kn">import</span> <span class="nn">os</span>

<span class="n">test_if_module_exists</span><span class="p">(</span><span class="s">&#39;Tkinter&#39;</span><span class="p">,</span> <span class="n">msg</span><span class="o">=</span><span class="s">&#39;You need to install the Tkinter package.&#39;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">Tkinter</span>
<span class="c"># use old behavior in Tkinter module to get around issue with Tcl</span>
<span class="c"># (more info: http://www.python.org/doc/2.3/whatsnew/node18.html)</span>
<span class="n">Tkinter</span><span class="o">.</span><span class="n">wantobjects</span> <span class="o">=</span> <span class="mi">0</span>

<span class="k">try</span><span class="p">:</span>
    <span class="kn">import</span> <span class="nn">vtkTkRenderWidget</span>
<span class="k">except</span><span class="p">:</span>
    <span class="kn">from</span> <span class="nn">vtk.tk</span> <span class="kn">import</span> <span class="n">vtkTkRenderWidget</span>

<span class="n">_vtk_options</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;mesa&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
                <span class="s">&#39;vtk_inc_dir&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;/usr/include/vtk-5.0&#39;</span><span class="p">],</span>
                <span class="s">&#39;vtk_lib_dir&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s">&#39;/usr/lib&#39;</span><span class="p">,</span>
                                <span class="s">&#39;/usr/lib/python-support/python-vtk/python2.5/vtk&#39;</span><span class="p">]}</span>
<span class="n">_update_from_config_file</span><span class="p">(</span><span class="n">_vtk_options</span><span class="p">,</span> <span class="n">section</span><span class="o">=</span><span class="s">&#39;vtk&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">_vtk_options</span><span class="p">[</span><span class="s">&#39;mesa&#39;</span><span class="p">]:</span>
    <span class="n">_graphics_fact</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkGraphicsFactory</span><span class="p">()</span>
    <span class="n">_graphics_fact</span><span class="o">.</span><span class="n">SetOffScreenOnlyMode</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">_graphics_fact</span><span class="o">.</span><span class="n">SetUseMesaClasses</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">_imaging_fact</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkImagingFactory</span><span class="p">()</span>
    <span class="n">_imaging_fact</span><span class="o">.</span><span class="n">SetUseMesaClasses</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">del</span> <span class="n">_graphics_fact</span>
    <span class="k">del</span> <span class="n">_imaging_fact</span>

<span class="c"># change these to suit your needs.</span>
<span class="n">inc_dirs</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;/usr/include/vtk-5.0&#39;</span><span class="p">]</span>
<span class="n">lib_dirs</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;/usr/lib&#39;</span><span class="p">,</span> <span class="s">&#39;/usr/lib/python-support/python-vtk/python2.5/vtk&#39;</span><span class="p">]</span>

<span class="k">if</span> <span class="n">OPTIMIZATION</span> <span class="o">==</span> <span class="s">&#39;weave&#39;</span><span class="p">:</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="kn">from</span> <span class="nn">scipy</span> <span class="kn">import</span> <span class="n">weave</span>
    <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">weave</span>
        <span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Weave not available. Optimization turned off.&quot;</span>


<span class="k">class</span> <span class="nc">_VTKFigure</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">plt</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">800</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">600</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">):</span>
        <span class="c"># create the GUI:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plt</span> <span class="o">=</span> <span class="n">plt</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">width</span> <span class="o">=</span> <span class="n">width</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">height</span> <span class="o">=</span> <span class="n">height</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">master</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">_master</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Toplevel</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">master</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="n">title</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">protocol</span><span class="p">(</span><span class="s">&quot;WM_DELETE_WINDOW&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">&quot;&lt;KeyPress-q&gt;&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">close</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">minsize</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span> <span class="mi">200</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">geometry</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">x</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">width</span><span class="p">,</span><span class="n">height</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">withdraw</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frame</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Frame</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="p">,</span> <span class="n">relief</span><span class="o">=</span><span class="s">&#39;sunken&#39;</span><span class="p">,</span> <span class="n">bd</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">frame</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span><span class="o">=</span><span class="s">&#39;top&#39;</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">,</span> <span class="n">expand</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tkw</span> <span class="o">=</span> <span class="n">vtkTkRenderWidget</span><span class="o">.</span><span class="n">vtkTkRenderWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">frame</span><span class="p">,</span>
                                                       <span class="n">width</span><span class="o">=</span><span class="n">width</span><span class="p">,</span>
                                                       <span class="n">height</span><span class="o">=</span><span class="n">height</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tkw</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span><span class="o">=</span><span class="s">&#39;true&#39;</span><span class="p">,</span> <span class="n">fill</span><span class="o">=</span><span class="s">&#39;both&#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">renwin</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tkw</span><span class="o">.</span><span class="n">GetRenderWindow</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">SetSize</span><span class="p">(</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># remove all renderers:</span>
        <span class="n">renderers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">GetRenderers</span><span class="p">()</span>
        <span class="n">ren</span> <span class="o">=</span> <span class="n">renderers</span><span class="o">.</span><span class="n">GetFirstRenderer</span><span class="p">()</span>
        <span class="k">while</span> <span class="n">ren</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">RemoveRenderer</span><span class="p">(</span><span class="n">ren</span><span class="p">)</span>
            <span class="n">ren</span> <span class="o">=</span> <span class="n">renderers</span><span class="o">.</span><span class="n">GetNextItem</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">plt</span><span class="o">.</span><span class="n">clf</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">withdraw</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">display</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">show</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">deiconify</span><span class="p">()</span>  <span class="c"># raise window</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>         <span class="c"># update window</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">render</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">render</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># First we render each of the axis renderers:</span>
        <span class="n">renderers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">GetRenderers</span><span class="p">()</span>
        <span class="n">ren</span> <span class="o">=</span> <span class="n">renderers</span><span class="o">.</span><span class="n">GetFirstRenderer</span><span class="p">()</span>
        <span class="k">while</span> <span class="n">ren</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">ren</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>
            <span class="n">ren</span> <span class="o">=</span> <span class="n">renderers</span><span class="o">.</span><span class="n">GetNextItem</span><span class="p">()</span>
        <span class="c"># Then we render the complete scene:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">Render</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">exit</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">destroy</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">set_size</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">geometry</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">x</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">width</span><span class="p">,</span><span class="n">height</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">update</span><span class="p">()</span>
        

<div class="viewcode-block" id="VTKBackend"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend">[docs]</a><span class="k">class</span> <span class="nc">VTKBackend</span><span class="p">(</span><span class="n">BaseClass</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">BaseClass</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_init</span><span class="p">()</span>
        
    <span class="k">def</span> <span class="nf">_init</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Perform initialization that is special for this backend.&quot;&quot;&quot;</span>
                
        <span class="bp">self</span><span class="o">.</span><span class="n">_master</span> <span class="o">=</span> <span class="n">Tkinter</span><span class="o">.</span><span class="n">Tk</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_master</span><span class="o">.</span><span class="n">withdraw</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;curfig&#39;</span><span class="p">))</span>
        
        <span class="c"># conversion tables for format strings:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_markers</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>   <span class="c"># no marker</span>
            <span class="s">&#39;.&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># dot</span>
            <span class="s">&#39;o&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># circle</span>
            <span class="s">&#39;x&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># cross</span>
            <span class="s">&#39;+&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># plus sign</span>
            <span class="s">&#39;*&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># asterisk</span>
            <span class="s">&#39;s&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># square</span>
            <span class="s">&#39;d&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># diamond</span>
            <span class="s">&#39;^&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># triangle (up)</span>
            <span class="s">&#39;v&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># triangle (down)</span>
            <span class="s">&#39;&lt;&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># triangle (left)</span>
            <span class="s">&#39;&gt;&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># triangle (right)</span>
            <span class="s">&#39;p&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># pentagram</span>
            <span class="s">&#39;h&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># hexagram</span>
            <span class="p">}</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_arrow_types</span> <span class="o">=</span> <span class="p">{</span>
            <span class="c"># tuple: (type,rotation)</span>
            <span class="s">&#39;&#39;</span><span class="p">:</span>  <span class="p">(</span><span class="mi">9</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># arrow</span>
            <span class="s">&#39;.&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># no marker</span>
            <span class="s">&#39;o&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">7</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># circle</span>
            <span class="s">&#39;+&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># plus</span>
            <span class="s">&#39;x&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">45</span><span class="p">),</span>  <span class="c"># x-mark</span>
            <span class="s">&#39;*&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># star --&gt; plus</span>
            <span class="s">&#39;s&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># square</span>
            <span class="s">&#39;d&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">8</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># diamond</span>
            <span class="s">&#39;v&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">180</span><span class="p">),</span> <span class="c"># triangle (down) </span>
            <span class="s">&#39;^&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># triangle (up)</span>
            <span class="s">&#39;&lt;&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">90</span><span class="p">),</span>  <span class="c"># triangle (left) </span>
            <span class="s">&#39;&gt;&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">270</span><span class="p">),</span> <span class="c"># triangle (right)</span>
            <span class="s">&#39;p&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># pentagram --&gt; square</span>
            <span class="s">&#39;h&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">6</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>   <span class="c"># hexagram --&gt; square</span>
            <span class="p">}</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>   <span class="c"># no color --&gt; blue</span>
            <span class="s">&#39;r&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>  <span class="c"># red</span>
            <span class="s">&#39;g&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>  <span class="c"># green</span>
            <span class="s">&#39;b&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span>  <span class="c"># blue</span>
            <span class="s">&#39;c&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span>  <span class="c"># cyan</span>
            <span class="s">&#39;m&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span>  <span class="c"># magenta</span>
            <span class="s">&#39;y&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>  <span class="c"># yellow</span>
            <span class="s">&#39;k&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span>  <span class="c"># black</span>
            <span class="s">&#39;w&#39;</span><span class="p">:</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">),</span>  <span class="c"># white</span>
            <span class="p">}</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_line_styles</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>    <span class="c"># no line </span>
            <span class="s">&#39;-&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>   <span class="c"># solid line</span>
            <span class="s">&#39;:&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>   <span class="c"># dotted line</span>
            <span class="s">&#39;-.&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># dash-dot line</span>
            <span class="s">&#39;--&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>  <span class="c"># dashed line</span>
            <span class="p">}</span>

        <span class="c"># convert table for colorbar location:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_colorbar_locations</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s">&#39;North&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="s">&#39;South&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="s">&#39;East&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="s">&#39;West&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="s">&#39;NorthOutside&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="s">&#39;SouthOutside&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="s">&#39;EastOutside&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="s">&#39;WestOutside&#39;</span><span class="p">:</span> <span class="bp">None</span><span class="p">,</span>
            <span class="p">}</span>

        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting backend standard variables&quot;</span>
            <span class="k">for</span> <span class="n">disp</span> <span class="ow">in</span> <span class="s">&#39;self._markers self._colors self._line_styles&#39;</span><span class="o">.</span><span class="n">split</span><span class="p">():</span>
                <span class="k">print</span> <span class="n">disp</span><span class="p">,</span> <span class="nb">eval</span><span class="p">(</span><span class="n">disp</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_get_color</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="p">(</span><span class="nb">tuple</span><span class="p">,</span><span class="nb">list</span><span class="p">))</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">color</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">):</span>
            <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">color</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">color</span> <span class="o">=</span> <span class="n">default</span>
        <span class="k">return</span> <span class="n">color</span>

    <span class="k">def</span> <span class="nf">_set_scale</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set linear or logarithmic (base 10) axis scale.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting scales&quot;</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;scale&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;loglog&#39;</span><span class="p">:</span>
            <span class="c"># use logarithmic scale on both x- and y-axis</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;logx&#39;</span><span class="p">:</span>
            <span class="c"># use logarithmic scale on x-axis and linear scale on y-axis</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;logy&#39;</span><span class="p">:</span>
            <span class="c"># use linear scale on x-axis and logarithmic scale on y-axis</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">scale</span> <span class="o">==</span> <span class="s">&#39;linear&#39;</span><span class="p">:</span>
            <span class="c"># use linear scale on both x- and y-axis</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_labels</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add text labels for x-, y-, and z-axis.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting labels&quot;</span>
        <span class="n">xlabel</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xlabel&#39;</span><span class="p">)</span>
        <span class="n">ylabel</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ylabel&#39;</span><span class="p">)</span>
        <span class="n">zlabel</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zlabel&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">xlabel</span><span class="p">:</span>
            <span class="c"># add a text label on x-axis</span>
            <span class="k">pass</span>
        <span class="k">if</span> <span class="n">ylabel</span><span class="p">:</span>
            <span class="c"># add a text label on y-axis</span>
            <span class="k">pass</span>
        <span class="k">if</span> <span class="n">zlabel</span><span class="p">:</span>
            <span class="c"># add a text label on z-axis</span>
            <span class="k">pass</span>
        
    <span class="k">def</span> <span class="nf">_set_title</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a title at the top of the axis.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting title&quot;</span>
        <span class="n">title</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;title&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">title</span><span class="p">:</span>
            <span class="n">tprop</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTextProperty</span><span class="p">()</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">BoldOff</span><span class="p">()</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetFontSize</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;fontsize&#39;</span><span class="p">))</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;fgcolor&#39;</span><span class="p">))</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetFontFamilyToArial</span><span class="p">()</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetVerticalJustificationToTop</span><span class="p">()</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetJustificationToCentered</span><span class="p">()</span>
            <span class="n">tmapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTextMapper</span><span class="p">()</span>
            <span class="n">tmapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">title</span><span class="p">)</span>
            <span class="n">tmapper</span><span class="o">.</span><span class="n">SetTextProperty</span><span class="p">(</span><span class="n">tprop</span><span class="p">)</span>
            <span class="n">tactor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor2D</span><span class="p">()</span>
            <span class="n">tactor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">tmapper</span><span class="p">)</span>
            <span class="n">tactor</span><span class="o">.</span><span class="n">GetPositionCoordinate</span><span class="p">()</span><span class="o">.</span><span class="n">SetCoordinateSystemToView</span><span class="p">()</span>
            <span class="n">tactor</span><span class="o">.</span><span class="n">GetPositionCoordinate</span><span class="p">()</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.95</span><span class="p">)</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">tactor</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">_set_limits</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set axis limits in x, y, and z direction.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting axis limits&quot;</span>
        <span class="n">mode</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;mode&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;auto&#39;</span><span class="p">:</span>
            <span class="c"># let plotting package set &#39;nice&#39; axis limits in the x, y,</span>
            <span class="c"># and z direction. If this is not automated in the plotting</span>
            <span class="c"># package, one can use the following limits:</span>
            <span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_limits</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;manual&#39;</span><span class="p">:</span>
            <span class="c"># (some) axis limits are frozen</span>
            <span class="n">xmin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmin&#39;</span><span class="p">)</span>
            <span class="n">xmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xmax&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">xmin</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">xmax</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># set x-axis limits</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># let plotting package set x-axis limits or use</span>
                <span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xlim&#39;</span><span class="p">)</span>

            <span class="n">ymin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ymin&#39;</span><span class="p">)</span>
            <span class="n">ymax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ymax&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">ymin</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">ymax</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># set y-axis limits</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># let plotting package set y-axis limits or use</span>
                <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ylim&#39;</span><span class="p">)</span>

            <span class="n">zmin</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zmin&#39;</span><span class="p">)</span>
            <span class="n">zmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zmax&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">zmin</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">zmax</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># set z-axis limits</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># let plotting package set z-axis limits or use</span>
                <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zlim&#39;</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;tight&#39;</span><span class="p">:</span>
            <span class="c"># set the limits on the axis to the range of the data. If</span>
            <span class="c"># this is not automated in the plotting package, one can</span>
            <span class="c"># use the following limits:</span>
            <span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_limits</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">mode</span> <span class="o">==</span> <span class="s">&#39;fill&#39;</span><span class="p">:</span>
            <span class="c"># not sure about this</span>
            <span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">get_limits</span><span class="p">()</span>

        <span class="n">limits</span> <span class="o">=</span> <span class="p">[</span><span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span><span class="p">]</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">_limits</span> <span class="o">=</span> <span class="p">(</span><span class="n">xmin</span><span class="p">,</span> <span class="n">xmax</span><span class="p">,</span> <span class="n">ymin</span><span class="p">,</span> <span class="n">ymax</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_position</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set axes position.&quot;&quot;&quot;</span>
        <span class="n">rect</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;viewport&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">rect</span><span class="p">:</span>
            <span class="c"># axes position is defined. In Matlab rect is defined as</span>
            <span class="c"># [left,bottom,width,height], where the four parameters are</span>
            <span class="c"># location values between 0 and 1 ((0,0) is the lower-left</span>
            <span class="c"># corner and (1,1) is the upper-right corner).</span>
            <span class="c"># NOTE: This can be different in the plotting package.</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_daspect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set data aspect ratio.&quot;&quot;&quot;</span>
        <span class="n">dar</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>  <span class="c"># dar is a list (len(dar) is 3).</span>
        <span class="c"># the axis limits are stored as ax._limits</span>
        <span class="n">l</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">_limits</span><span class="p">)</span>
        <span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">/=</span> <span class="n">dar</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span>  <span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">/=</span> <span class="n">dar</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">l</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">/=</span> <span class="n">dar</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span>  <span class="n">l</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">/=</span> <span class="n">dar</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">l</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="o">/=</span> <span class="n">dar</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span>  <span class="n">l</span><span class="p">[</span><span class="mi">5</span><span class="p">]</span> <span class="o">/=</span> <span class="n">dar</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">_scaled_limits</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
        
    <span class="k">def</span> <span class="nf">_set_axis_method</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="n">method</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;method&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;equal&#39;</span><span class="p">:</span>
            <span class="c"># tick mark increments on the x-, y-, and z-axis should</span>
            <span class="c"># be equal in size.</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;image&#39;</span><span class="p">:</span>
            <span class="c"># same effect as axis(&#39;equal&#39;) and axis(&#39;tight&#39;)</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;square&#39;</span><span class="p">:</span>
            <span class="c"># make the axis box square in size</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;normal&#39;</span><span class="p">:</span>
            <span class="c"># full size axis box</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">method</span> <span class="o">==</span> <span class="s">&#39;vis3d&#39;</span><span class="p">:</span>
            <span class="c"># freeze data aspect ratio when rotating 3D objects</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_coordinate_system</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Use either the default Cartesian coordinate system or a</span>
<span class="sd">        matrix coordinate system.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="n">direction</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;direction&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">direction</span> <span class="o">==</span> <span class="s">&#39;ij&#39;</span><span class="p">:</span>
            <span class="c"># Use matrix coordinates. The origin of the coordinate</span>
            <span class="c"># system is the upper-left corner. The i-axis should be</span>
            <span class="c"># vertical and numbered from top to bottom, while the j-axis</span>
            <span class="c"># should be horizontal and numbered from left to right.</span>
            <span class="k">pass</span>
        <span class="k">elif</span> <span class="n">direction</span> <span class="o">==</span> <span class="s">&#39;xy&#39;</span><span class="p">:</span>
            <span class="c"># use the default Cartesian axes form. The origin is at the</span>
            <span class="c"># lower-left corner. The x-axis is vertical and numbered</span>
            <span class="c"># from left to right, while the y-axis is vertical and</span>
            <span class="c"># numbered from bottom to top.</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_box</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Turn box around axes boundary on or off.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting box&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;box&#39;</span><span class="p">):</span>
            <span class="c"># display box </span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># do not display box</span>
            <span class="k">pass</span>
        
    <span class="k">def</span> <span class="nf">_set_grid</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Turn grid lines on or off.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting grid&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;grid&#39;</span><span class="p">):</span>
            <span class="c"># turn grid lines on</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn grid lines off</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_hidden_line_removal</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Turn on/off hidden line removal for meshes.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting hidden line removal&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;hidden&#39;</span><span class="p">):</span>
            <span class="c"># turn hidden line removal on</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn hidden line removal off</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_colorbar</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a colorbar to the axis.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting colorbar&quot;</span>
        <span class="n">cbar</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;colorbar&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">cbar</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;visible&#39;</span><span class="p">):</span>
            <span class="c"># turn on colorbar</span>
            <span class="n">cbar_title</span> <span class="o">=</span> <span class="n">cbar</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cbtitle&#39;</span><span class="p">)</span>
            <span class="n">cbar_location</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colorbar_locations</span><span class="p">[</span><span class="n">cbar</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cblocation&#39;</span><span class="p">)]</span>
            <span class="c"># ...</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn off colorbar</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_set_caxis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the color axis scale.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting caxis&quot;</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;caxismode&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;manual&#39;</span><span class="p">:</span>
            <span class="n">cmin</span><span class="p">,</span> <span class="n">cmax</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;caxis&#39;</span><span class="p">)</span>
            <span class="c"># NOTE: cmin and cmax might be None:</span>
            <span class="k">if</span> <span class="n">cmin</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">cmax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">cmin</span><span class="p">,</span> <span class="n">cmax</span> <span class="o">=</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">]</span>
            <span class="c"># set color axis scaling according to cmin and cmax</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">_caxis</span> <span class="o">=</span> <span class="p">(</span><span class="n">cmin</span><span class="p">,</span> <span class="n">cmax</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># use autoranging for color axis scale</span>
            <span class="n">ax</span><span class="o">.</span><span class="n">_caxis</span> <span class="o">=</span> <span class="bp">None</span>

    <span class="k">def</span> <span class="nf">_set_colormap</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set the colormap.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting colormap&quot;</span>
        <span class="n">cmap</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;colormap&#39;</span><span class="p">)</span>
        <span class="c"># cmap is plotting package dependent</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">cmap</span><span class="p">,</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">):</span>
            <span class="n">cmap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">jet</span><span class="p">()</span>  <span class="c"># use default colormap</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">_colormap</span> <span class="o">=</span> <span class="n">cmap</span>

    <span class="k">def</span> <span class="nf">_set_view</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set viewpoint specification.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting view&quot;</span>
        <span class="n">cam</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camera&#39;</span><span class="p">)</span>

        <span class="n">view</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;view&#39;</span><span class="p">)</span>

        <span class="n">fp</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camtarget&#39;</span><span class="p">)</span>
        <span class="n">camera</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCamera</span><span class="p">()</span>
        <span class="n">camera</span><span class="o">.</span><span class="n">SetFocalPoint</span><span class="p">(</span><span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camtarget&#39;</span><span class="p">))</span>
        <span class="n">camera</span><span class="o">.</span><span class="n">SetViewUp</span><span class="p">(</span><span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camup&#39;</span><span class="p">))</span>
        <span class="n">camera</span><span class="o">.</span><span class="n">ParallelProjectionOn</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">view</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c"># setup a default 2D view</span>
            <span class="n">camera</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="n">fp</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">fp</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="mi">1</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">view</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
            <span class="n">camera</span><span class="o">.</span><span class="n">SetPosition</span><span class="p">(</span><span class="n">fp</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">fp</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="n">fp</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
            <span class="n">az</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;azimuth&#39;</span><span class="p">)</span>
            <span class="n">el</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;elevation&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">az</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">or</span> <span class="n">el</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># azimuth or elevation is not given. Set up a default</span>
                <span class="c"># 3D view (az=-37.5 and el=30 is the default 3D view in</span>
                <span class="c"># Matlab).</span>
                <span class="n">az</span> <span class="o">=</span> <span class="o">-</span><span class="mf">37.5</span>
                <span class="n">el</span> <span class="o">=</span> <span class="mi">30</span>
            <span class="c"># set a 3D view according to az and el</span>
            <span class="n">camera</span><span class="o">.</span><span class="n">Azimuth</span><span class="p">(</span><span class="n">az</span><span class="p">)</span>
            <span class="n">camera</span><span class="o">.</span><span class="n">Elevation</span><span class="p">(</span><span class="n">el</span><span class="p">)</span>                
            
            <span class="k">if</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cammode&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;manual&#39;</span><span class="p">:</span>
                <span class="c"># for advanced camera handling:</span>
                <span class="n">roll</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camroll&#39;</span><span class="p">)</span>
                <span class="n">zoom</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camzoom&#39;</span><span class="p">)</span>
                <span class="n">dolly</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camdolly&#39;</span><span class="p">)</span>
                <span class="n">target</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camtarget&#39;</span><span class="p">)</span>
                <span class="n">position</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;campos&#39;</span><span class="p">)</span>
                <span class="n">up_vector</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camup&#39;</span><span class="p">)</span>
                <span class="n">view_angle</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camva&#39;</span><span class="p">)</span>
                <span class="n">projection</span> <span class="o">=</span> <span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camproj&#39;</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">projection</span> <span class="o">==</span> <span class="s">&#39;perspective&#39;</span><span class="p">:</span>
                    <span class="n">camera</span><span class="o">.</span><span class="n">ParallelProjectionOff</span><span class="p">()</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">camera</span><span class="o">.</span><span class="n">ParallelProjectionOn</span><span class="p">()</span>
            

        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">SetActiveCamera</span><span class="p">(</span><span class="n">camera</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_camera</span> <span class="o">=</span> <span class="n">camera</span>

        <span class="c"># make sure all actors are inside the current view:</span>
        <span class="n">ren</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span>
        <span class="n">ren</span><span class="o">.</span><span class="n">ResetCamera</span><span class="p">()</span>
        <span class="c">#if self._ax.getp(&#39;camera&#39;).getp(&#39;view&#39;) == 2:</span>
        <span class="c">#    ren.GetActiveCamera().Zoom(1.5)</span>
        <span class="n">camera</span><span class="o">.</span><span class="n">Zoom</span><span class="p">(</span><span class="n">cam</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;camzoom&#39;</span><span class="p">))</span>
       
        <span class="c"># set the camera in the vtkCubeAxesActor2D object:</span>
        <span class="c">#self._ax._vtk_axes.SetCamera(camera)</span>


    <span class="k">def</span> <span class="nf">_set_axis_props</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting axis properties&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_title</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_scale</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_limits</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_position</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_axis_method</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_daspect</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_coordinate_system</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_hidden_line_removal</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_colorbar</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_caxis</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_colormap</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_view</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;visible&#39;</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_labels</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_box</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_grid</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># turn off all axis labeling, tickmarks, and background</span>
            <span class="k">pass</span>
        
    <span class="k">def</span> <span class="nf">_is_inside_limits</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return True if data limits is inside axis limits.&quot;&quot;&quot;</span>
        <span class="n">slim</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_scaled_limits</span>
        <span class="n">dlim</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">GetBounds</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">slim</span><span class="p">),</span> <span class="mi">2</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">dlim</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">slim</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">allclose</span><span class="p">(</span><span class="n">dlim</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">slim</span><span class="p">[</span><span class="n">i</span><span class="p">]):</span>
                <span class="k">return</span> <span class="bp">False</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">slim</span><span class="p">),</span> <span class="mi">2</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">dlim</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">slim</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">allclose</span><span class="p">(</span><span class="n">dlim</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">slim</span><span class="p">[</span><span class="n">i</span><span class="p">]):</span>
                <span class="k">return</span> <span class="bp">False</span>
        <span class="k">return</span> <span class="bp">True</span>

    <span class="k">def</span> <span class="nf">_cut_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return cutted data if limits is outside (scaled) axis limits.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_inside_limits</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()):</span>
            <span class="k">return</span> <span class="n">data</span>
        <span class="n">box</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkBox</span><span class="p">()</span>
        <span class="n">box</span><span class="o">.</span><span class="n">SetBounds</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_scaled_limits</span><span class="p">)</span>
        <span class="n">clipper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkClipPolyData</span><span class="p">()</span>
        <span class="n">clipper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="n">clipper</span><span class="o">.</span><span class="n">SetClipFunction</span><span class="p">(</span><span class="n">box</span><span class="p">)</span>
        <span class="c">#clipper.GenerateClipScalarsOn()</span>
        <span class="c">#clipper.GenerateClippedOutputOn()</span>
        <span class="n">clipper</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="n">clipper</span><span class="o">.</span><span class="n">InsideOutOn</span><span class="p">()</span>
        <span class="n">clipper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">clipper</span>

    <span class="k">def</span> <span class="nf">_set_shading</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">actor</span><span class="p">):</span>
        <span class="n">shading</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;shading&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">shading</span> <span class="o">==</span> <span class="s">&#39;interp&#39;</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetInterpolationToGouraud</span><span class="p">()</span>
        <span class="k">elif</span> <span class="n">shading</span> <span class="o">==</span> <span class="s">&#39;flat&#39;</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetInterpolationToFlat</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># use &#39;faceted&#39; as the default shading</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetInterpolationToFlat</span><span class="p">()</span>
            <span class="n">edges</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkExtractEdges</span><span class="p">()</span>
            <span class="n">edges</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">source</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="n">edges</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
            <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">edges</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">ScalarVisibilityOff</span><span class="p">()</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetResolveCoincidentTopologyToPolygonOffset</span><span class="p">()</span>
            <span class="n">mesh</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
            <span class="n">mesh</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
            <span class="n">edgecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;edgecolor&#39;</span><span class="p">),</span> <span class="bp">None</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">edgecolor</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c"># try items linecolor property:</span>
                <span class="n">edgecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linecolor&#39;</span><span class="p">),</span> <span class="bp">None</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">edgecolor</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">edgecolor</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>  <span class="c"># use black as default edge color</span>
            <span class="n">mesh</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">edgecolor</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">mesh</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_actor_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">):</span>
        <span class="c"># set line properties:</span>
        <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_color</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linecolor&#39;</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linetype&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;--&#39;</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineStipplePattern</span><span class="p">(</span><span class="mi">65280</span><span class="p">)</span>
        <span class="k">elif</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linetype&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s">&#39;:&#39;</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineStipplePattern</span><span class="p">(</span><span class="mh">0x1111</span><span class="p">)</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineStippleRepeatFactor</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="c">#actor.GetProperty().SetPointSize(item.getp(&#39;pointsize&#39;))</span>
        <span class="n">linewidth</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linewidth&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">linewidth</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetLineWidth</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">linewidth</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">_set_actor_material_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">):</span>
        <span class="c"># set material properties:</span>
        <span class="n">ax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span>
        <span class="n">mat</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;material&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;opacity&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetOpacity</span><span class="p">(</span><span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;opacity&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ambient&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetAmbient</span><span class="p">(</span><span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ambient&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ambientcolor&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetAmbientColor</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ambientcolor&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;diffuse&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetDiffuse</span><span class="p">(</span><span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;diffuse&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;diffusecolor&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetDiffuseColor</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;diffusecolor&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;specular&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetSpecular</span><span class="p">(</span><span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;specular&#39;</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;specularpower&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetSpecularPower</span><span class="p">(</span><span class="n">mat</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;specularpower&#39;</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">_create_2D_scalar_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">))</span>  <span class="c"># grid component in x-direction</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">))</span>  <span class="c"># grid component in y-direction</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">))</span>  <span class="c"># scalar field</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cdata&#39;</span><span class="p">)</span>       <span class="c"># pseudocolor data</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">z</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">c</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">z</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">c</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
        <span class="k">assert</span> <span class="n">shape</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">):</span>
            <span class="k">assert</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span>
            <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">meshgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">sparse</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">indexing</span><span class="o">=</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">))</span>
            <span class="c"># FIXME: use ndgrid instead of meshgrid</span>
        <span class="k">assert</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span>
        
        <span class="c"># scale x, y, and z according to data aspect ratio:</span>
        <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">/</span><span class="n">dx</span><span class="p">;</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="o">/</span><span class="n">dy</span><span class="p">;</span>  <span class="n">z</span> <span class="o">=</span> <span class="n">z</span><span class="o">/</span><span class="n">dz</span>
        
        <span class="n">function</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;function&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">function</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;contour&#39;</span><span class="p">,</span> <span class="s">&#39;contourf&#39;</span><span class="p">,</span> <span class="s">&#39;pcolor&#39;</span><span class="p">]:</span>
            <span class="n">z</span> <span class="o">*=</span> <span class="mi">0</span>
        <span class="k">if</span> <span class="n">function</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;meshc&#39;</span><span class="p">,</span> <span class="s">&#39;surfc&#39;</span><span class="p">]</span> <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Contours</span><span class="p">):</span>
            <span class="c"># this item is the Contours object beneath the surface in</span>
            <span class="c"># a meshc or surfc plot.</span>
            <span class="n">z</span> <span class="o">*=</span> <span class="mi">0</span>
            <span class="n">z</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_scaled_limits</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span>
        
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">points</span><span class="o">.</span><span class="n">SetNumberOfPoints</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofpoints&#39;</span><span class="p">))</span>
        <span class="n">scalars</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkFloatArray</span><span class="p">()</span>
        <span class="n">scalars</span><span class="o">.</span><span class="n">SetNumberOfTuples</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofpoints&#39;</span><span class="p">))</span>
        <span class="n">scalars</span><span class="o">.</span><span class="n">SetNumberOfComponents</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">nx</span><span class="p">,</span> <span class="n">ny</span> <span class="o">=</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">OPTIMIZATION</span> <span class="o">==</span> <span class="s">&#39;weave&#39;</span><span class="p">:</span>
            <span class="n">code</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">int ind=0;</span>
<span class="s">for (int j=0; j&lt;ny; j++) {</span>
<span class="s">    for (int i=0; i&lt;nx; i++) {</span>
<span class="s">        points-&gt;SetPoint(ind, x(i,j), y(i,j), z(i,j));</span>
<span class="s">        scalars-&gt;SetValue(ind, c(i,j));</span>
<span class="s">        ind += 1;</span>
<span class="s">    }</span>
<span class="s">}</span>
<span class="s">&quot;&quot;&quot;</span>
            <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;nx&#39;</span><span class="p">,</span> <span class="s">&#39;ny&#39;</span><span class="p">,</span> <span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;y&#39;</span><span class="p">,</span> <span class="s">&#39;z&#39;</span><span class="p">,</span> <span class="s">&#39;c&#39;</span><span class="p">,</span> <span class="s">&#39;points&#39;</span><span class="p">,</span> <span class="s">&#39;scalars&#39;</span><span class="p">]</span>
            <span class="n">weave</span><span class="o">.</span><span class="n">inline</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span>
                         <span class="n">include_dirs</span><span class="o">=</span><span class="n">inc_dirs</span><span class="p">,</span> <span class="n">library_dirs</span><span class="o">=</span><span class="n">lib_dirs</span><span class="p">,</span>
                         <span class="n">type_converters</span><span class="o">=</span><span class="n">weave</span><span class="o">.</span><span class="n">converters</span><span class="o">.</span><span class="n">blitz</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ind</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ny</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nx</span><span class="p">):</span>
                    <span class="n">points</span><span class="o">.</span><span class="n">SetPoint</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">],</span> <span class="n">z</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">])</span>
                    <span class="n">scalars</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">c</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">])</span>
                    <span class="n">ind</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">points</span><span class="o">.</span><span class="n">Modified</span><span class="p">()</span>
        <span class="n">sgrid</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGrid</span><span class="p">()</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetDimensions</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;dims&#39;</span><span class="p">))</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">GetPointData</span><span class="p">()</span><span class="o">.</span><span class="n">SetScalars</span><span class="p">(</span><span class="n">scalars</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">sgrid</span>

    <span class="k">def</span> <span class="nf">_create_2D_vector_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">))</span>  <span class="c"># grid component in x-direction</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">))</span>  <span class="c"># grid component in y-direction</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>           <span class="c"># scalar field</span>
        <span class="c"># vector components:</span>
        <span class="n">u</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;udata&#39;</span><span class="p">))</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">))</span>
        <span class="n">w</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;wdata&#39;</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="n">z</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">z</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">z</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">z</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">w</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">w</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">w</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">w</span><span class="p">)</span>

        <span class="c"># scale x, y, and z according to data aspect ratio:</span>
        <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">/</span><span class="n">dx</span><span class="p">;</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="o">/</span><span class="n">dy</span><span class="p">;</span>  <span class="n">z</span> <span class="o">=</span> <span class="n">z</span><span class="o">/</span><span class="n">dz</span>
        
        <span class="k">if</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">):</span>
            <span class="k">assert</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span>
            <span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">meshgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">sparse</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">indexing</span><span class="o">=</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">))</span>
            <span class="c"># FIXME: use ndgrid instead of meshgrid</span>
        <span class="k">assert</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> \
               <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> \
               <span class="n">shape</span><span class="p">(</span><span class="n">w</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>

        <span class="n">n</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofpoints&#39;</span><span class="p">)</span>
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">points</span><span class="o">.</span><span class="n">SetNumberOfPoints</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
        <span class="n">vectors</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkFloatArray</span><span class="p">()</span>
        <span class="n">vectors</span><span class="o">.</span><span class="n">SetNumberOfTuples</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
        <span class="n">vectors</span><span class="o">.</span><span class="n">SetNumberOfComponents</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">vectors</span><span class="o">.</span><span class="n">SetNumberOfValues</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">n</span><span class="p">)</span>
        <span class="n">nx</span><span class="p">,</span> <span class="n">ny</span> <span class="o">=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">OPTIMIZATION</span> <span class="o">==</span> <span class="s">&#39;weave&#39;</span><span class="p">:</span>
            <span class="n">code</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">int ind=0;</span>
<span class="s">for (int j=0; j&lt;ny; j++) {</span>
<span class="s">    for (int i=0; i&lt;nx; i++) {</span>
<span class="s">        points-&gt;SetPoint(ind, x(i,j), y(i,j), z(i,j));</span>
<span class="s">        vectors-&gt;SetTuple3(ind, u(i,j), v(i,j), w(i,j));</span>
<span class="s">        ind += 1;</span>
<span class="s">    }</span>
<span class="s">}</span>
<span class="s">&quot;&quot;&quot;</span>
            <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;nx&#39;</span><span class="p">,</span> <span class="s">&#39;ny&#39;</span><span class="p">,</span> <span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;y&#39;</span><span class="p">,</span> <span class="s">&#39;z&#39;</span><span class="p">,</span>
                    <span class="s">&#39;u&#39;</span><span class="p">,</span> <span class="s">&#39;v&#39;</span><span class="p">,</span> <span class="s">&#39;w&#39;</span><span class="p">,</span> <span class="s">&#39;points&#39;</span><span class="p">,</span> <span class="s">&#39;vectors&#39;</span><span class="p">]</span>
            <span class="n">weave</span><span class="o">.</span><span class="n">inline</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span>
                         <span class="n">include_dirs</span><span class="o">=</span><span class="n">inc_dirs</span><span class="p">,</span> <span class="n">library_dirs</span><span class="o">=</span><span class="n">lib_dirs</span><span class="p">,</span>
                         <span class="n">type_converters</span><span class="o">=</span><span class="n">weave</span><span class="o">.</span><span class="n">converters</span><span class="o">.</span><span class="n">blitz</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ind</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ny</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nx</span><span class="p">):</span>
                    <span class="n">points</span><span class="o">.</span><span class="n">SetPoint</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">],</span> <span class="n">z</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">])</span>
                    <span class="n">vectors</span><span class="o">.</span><span class="n">SetTuple3</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">u</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">],</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">],</span> <span class="n">w</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">])</span>
                    <span class="n">ind</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">points</span><span class="o">.</span><span class="n">Modified</span><span class="p">()</span>
        <span class="n">sgrid</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGrid</span><span class="p">()</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetDimensions</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;dims&#39;</span><span class="p">))</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">GetPointData</span><span class="p">()</span><span class="o">.</span><span class="n">SetVectors</span><span class="p">(</span><span class="n">vectors</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">sgrid</span>

    <span class="k">def</span> <span class="nf">_create_3D_scalar_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">))</span>  <span class="c"># grid component in x-direction</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">))</span>  <span class="c"># grid component in y-direction</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">))</span>  <span class="c"># grid component in z-direction</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">))</span>  <span class="c"># scalar data</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cdata&#39;</span><span class="p">)</span>           <span class="c"># pseudocolor data</span>
        <span class="c"># FIXME: What about pseudocolor data?</span>
        
        <span class="k">if</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> \
               <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">):</span>
            <span class="k">assert</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span>
            <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span> <span class="o">=</span> <span class="n">meshgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="p">,</span><span class="n">sparse</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">indexing</span><span class="o">=</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">))</span>
            <span class="c"># FIXME: use ndgrid instead of meshgrid</span>
        <span class="k">assert</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> \
               <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
        
        <span class="c"># scale x, y, and z according to data aspect ratio:</span>
        <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">/</span><span class="n">dx</span><span class="p">;</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="o">/</span><span class="n">dy</span><span class="p">;</span>  <span class="n">z</span> <span class="o">=</span> <span class="n">z</span><span class="o">/</span><span class="n">dz</span>
        
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">points</span><span class="o">.</span><span class="n">SetNumberOfPoints</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofpoints&#39;</span><span class="p">))</span>
        <span class="n">scalars</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkFloatArray</span><span class="p">()</span>
        <span class="n">scalars</span><span class="o">.</span><span class="n">SetNumberOfTuples</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofpoints&#39;</span><span class="p">))</span>
        <span class="n">scalars</span><span class="o">.</span><span class="n">SetNumberOfComponents</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">nx</span><span class="p">,</span> <span class="n">ny</span><span class="p">,</span> <span class="n">nz</span> <span class="o">=</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">OPTIMIZATION</span> <span class="o">==</span> <span class="s">&#39;weave&#39;</span><span class="p">:</span>
            <span class="n">code</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">int ind=0;</span>
<span class="s">for (int k=0; k&lt;nz; k++) {</span>
<span class="s">    for (int j=0; j&lt;ny; j++) {</span>
<span class="s">        for (int i=0; i&lt;nx; i++) {</span>
<span class="s">            points-&gt;SetPoint(ind, x(i,j,k), y(i,j,k), z(i,j,k));</span>
<span class="s">            scalars-&gt;SetValue(ind, v(i,j,k));</span>
<span class="s">            ind += 1;</span>
<span class="s">        }</span>
<span class="s">    }</span>
<span class="s">}</span>
<span class="s">&quot;&quot;&quot;</span>
            <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;nx&#39;</span><span class="p">,</span> <span class="s">&#39;ny&#39;</span><span class="p">,</span> <span class="s">&#39;nz&#39;</span><span class="p">,</span> <span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;y&#39;</span><span class="p">,</span> <span class="s">&#39;z&#39;</span><span class="p">,</span> <span class="s">&#39;v&#39;</span><span class="p">,</span> <span class="s">&#39;points&#39;</span><span class="p">,</span> <span class="s">&#39;scalars&#39;</span><span class="p">]</span>
            <span class="n">weave</span><span class="o">.</span><span class="n">inline</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span>
                         <span class="n">include_dirs</span><span class="o">=</span><span class="n">inc_dirs</span><span class="p">,</span> <span class="n">library_dirs</span><span class="o">=</span><span class="n">lib_dirs</span><span class="p">,</span>
                         <span class="n">type_converters</span><span class="o">=</span><span class="n">weave</span><span class="o">.</span><span class="n">converters</span><span class="o">.</span><span class="n">blitz</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ind</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nz</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ny</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nx</span><span class="p">):</span>
                        <span class="n">points</span><span class="o">.</span><span class="n">SetPoint</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">],</span> <span class="n">z</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">])</span>
                        <span class="n">scalars</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">])</span>
                        <span class="n">ind</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">points</span><span class="o">.</span><span class="n">Modified</span><span class="p">()</span>
        <span class="n">sgrid</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGrid</span><span class="p">()</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetDimensions</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;dims&#39;</span><span class="p">))</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">GetPointData</span><span class="p">()</span><span class="o">.</span><span class="n">SetScalars</span><span class="p">(</span><span class="n">scalars</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">sgrid</span>

    <span class="k">def</span> <span class="nf">_create_3D_vector_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">))</span>  <span class="c"># grid component in x-direction</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">))</span>  <span class="c"># grid component in y-direction</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">squeeze</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">))</span>  <span class="c"># grid component in z-direction</span>
        <span class="c"># vector components:</span>
        <span class="n">u</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;udata&#39;</span><span class="p">))</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">))</span>
        <span class="n">w</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;wdata&#39;</span><span class="p">))</span>
        
        <span class="c"># scale x, y, and z according to data aspect ratio:</span>
        <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">x</span><span class="o">/</span><span class="n">dx</span><span class="p">;</span>  <span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="o">/</span><span class="n">dy</span><span class="p">;</span>  <span class="n">z</span> <span class="o">=</span> <span class="n">z</span><span class="o">/</span><span class="n">dz</span>
        
        <span class="k">if</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> \
               <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="o">!=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">):</span>
            <span class="k">assert</span> <span class="n">rank</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">rank</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span>
            <span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span> <span class="o">=</span> <span class="n">meshgrid</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">,</span><span class="n">z</span><span class="p">,</span><span class="n">sparse</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span><span class="n">indexing</span><span class="o">=</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;indexing&#39;</span><span class="p">))</span>
            <span class="c"># FIXME: use ndgrid instead of meshgrid</span>
        <span class="k">assert</span> <span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> \
               <span class="n">shape</span><span class="p">(</span><span class="n">z</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> <span class="n">shape</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span> <span class="ow">and</span> \
               <span class="n">shape</span><span class="p">(</span><span class="n">w</span><span class="p">)</span> <span class="o">==</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>

        <span class="n">n</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofpoints&#39;</span><span class="p">)</span>
        <span class="n">points</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPoints</span><span class="p">()</span>
        <span class="n">points</span><span class="o">.</span><span class="n">SetNumberOfPoints</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
        <span class="n">vectors</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkFloatArray</span><span class="p">()</span>
        <span class="n">vectors</span><span class="o">.</span><span class="n">SetNumberOfTuples</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
        <span class="n">vectors</span><span class="o">.</span><span class="n">SetNumberOfComponents</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="n">vectors</span><span class="o">.</span><span class="n">SetNumberOfValues</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">n</span><span class="p">)</span>
        <span class="n">nx</span><span class="p">,</span> <span class="n">ny</span><span class="p">,</span> <span class="n">nz</span> <span class="o">=</span> <span class="n">shape</span><span class="p">(</span><span class="n">u</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">OPTIMIZATION</span> <span class="o">==</span> <span class="s">&#39;weave&#39;</span><span class="p">:</span>
            <span class="n">code</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">int ind=0;</span>
<span class="s">for (int k=0; k&lt;nz; k++) {</span>
<span class="s">    for (int j=0; j&lt;ny; j++) {</span>
<span class="s">        for (int i=0; i&lt;nx; i++) {</span>
<span class="s">            points-&gt;SetPoint(ind, x(i,j,k), y(i,j,k), z(i,j,k));</span>
<span class="s">            vectors-&gt;SetTuple3(ind, u(i,j,k), v(i,j,k), w(i,j,k));</span>
<span class="s">            ind += 1;</span>
<span class="s">        }</span>
<span class="s">    }</span>
<span class="s">}</span>
<span class="s">&quot;&quot;&quot;</span>
            <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;nx&#39;</span><span class="p">,</span> <span class="s">&#39;ny&#39;</span><span class="p">,</span> <span class="s">&#39;nz&#39;</span><span class="p">,</span> <span class="s">&#39;x&#39;</span><span class="p">,</span> <span class="s">&#39;y&#39;</span><span class="p">,</span> <span class="s">&#39;z&#39;</span><span class="p">,</span>
                    <span class="s">&#39;u&#39;</span><span class="p">,</span> <span class="s">&#39;v&#39;</span><span class="p">,</span> <span class="s">&#39;w&#39;</span><span class="p">,</span> <span class="s">&#39;points&#39;</span><span class="p">,</span> <span class="s">&#39;vectors&#39;</span><span class="p">]</span>
            <span class="n">weave</span><span class="o">.</span><span class="n">inline</span><span class="p">(</span><span class="n">code</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span>
                         <span class="n">include_dirs</span><span class="o">=</span><span class="n">inc_dirs</span><span class="p">,</span> <span class="n">library_dirs</span><span class="o">=</span><span class="n">lib_dirs</span><span class="p">,</span>
                         <span class="n">type_converters</span><span class="o">=</span><span class="n">weave</span><span class="o">.</span><span class="n">converters</span><span class="o">.</span><span class="n">blitz</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">ind</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nz</span><span class="p">):</span>
                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">ny</span><span class="p">):</span>
                    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">nx</span><span class="p">):</span>
                        <span class="n">points</span><span class="o">.</span><span class="n">SetPoint</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">],</span> <span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">],</span> <span class="n">z</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">])</span>
                        <span class="n">vectors</span><span class="o">.</span><span class="n">SetTuple3</span><span class="p">(</span><span class="n">ind</span><span class="p">,</span> <span class="n">u</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">],</span> <span class="n">v</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">],</span> <span class="n">w</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">,</span><span class="n">k</span><span class="p">])</span>
                        <span class="n">ind</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">points</span><span class="o">.</span><span class="n">Modified</span><span class="p">()</span>
        <span class="n">sgrid</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGrid</span><span class="p">()</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetDimensions</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;dims&#39;</span><span class="p">))</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">SetPoints</span><span class="p">(</span><span class="n">points</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">GetPointData</span><span class="p">()</span><span class="o">.</span><span class="n">SetVectors</span><span class="p">(</span><span class="n">vectors</span><span class="p">)</span>
        <span class="n">sgrid</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">sgrid</span>

    <span class="k">def</span> <span class="nf">_get_linespecs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the line marker, line color, line style, and</span>
<span class="sd">        line width of the item.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">marker</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_markers</span><span class="p">[</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linemarker&#39;</span><span class="p">)]</span>
        <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="p">[</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linecolor&#39;</span><span class="p">)]</span>
        <span class="n">style</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_line_styles</span><span class="p">[</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linetype&#39;</span><span class="p">)]</span>
        <span class="n">width</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linewidth&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span>

    <span class="k">def</span> <span class="nf">_add_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add a 2D or 3D curve to the scene.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a line&quot;</span>
        <span class="c"># get data:</span>
        <span class="n">x</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">)</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">)</span>
        <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="c"># get line specifiactions:</span>
        <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_linespecs</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">z</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># zdata is given, add a 3D curve:</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># no zdata, add a 2D curve:</span>
            <span class="k">pass</span>

    <span class="k">def</span> <span class="nf">_add_surface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">shading</span><span class="o">=</span><span class="s">&#39;faceted&#39;</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a surface&quot;</span>

        <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_2D_scalar_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
        
        <span class="n">contours</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;contours&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">contours</span><span class="p">:</span>
            <span class="c"># the current item is produced by meshc or surfc and we</span>
            <span class="c"># should therefore add contours at the bottom:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_add_contours</span><span class="p">(</span><span class="n">contours</span><span class="p">,</span> <span class="n">placement</span><span class="o">=</span><span class="s">&#39;bottom&#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;wireframe&#39;</span><span class="p">):</span>
            <span class="c"># wireframe mesh (as produced by mesh or meshc)</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># colored surface (as produced by surf, surfc, or pcolor)</span>
            <span class="c"># use keyword argument shading to set the color shading mode</span>
            <span class="k">pass</span>
        <span class="n">plane</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGridGeometryFilter</span><span class="p">()</span>
        <span class="n">plane</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid</span><span class="p">)</span>
        <span class="n">plane</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cut_data</span><span class="p">(</span><span class="n">plane</span><span class="p">)</span>
        <span class="n">normals</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataNormals</span><span class="p">()</span>
        <span class="n">normals</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="n">normals</span><span class="o">.</span><span class="n">SetFeatureAngle</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
        <span class="n">normals</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkDataSetMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">normals</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetLookupTable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_colormap</span><span class="p">)</span>
        <span class="n">cax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_caxis</span>
        <span class="k">if</span> <span class="n">cax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">cax</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetScalarRange</span><span class="p">(</span><span class="n">cax</span><span class="p">)</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;wireframe&#39;</span><span class="p">):</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetRepresentationToWireframe</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_shading</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_actor_properties</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
        <span class="c">#self._add_legend(item, normals.GetOutput())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">normals</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">_add_contours</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">placement</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="c"># The placement keyword can be either None or &#39;bottom&#39;. The</span>
        <span class="c"># latter specifies that the contours should be placed at the</span>
        <span class="c"># bottom (as in meshc or surfc).</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding contours&quot;</span>
            
        <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_2D_scalar_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
        <span class="n">plane</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGridGeometryFilter</span><span class="p">()</span>
        <span class="n">plane</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid</span><span class="p">)</span>
        <span class="n">plane</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cut_data</span><span class="p">(</span><span class="n">plane</span><span class="p">)</span>

        <span class="n">filled</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;filled&#39;</span><span class="p">)</span>  <span class="c"># draw filled contour plot if True</span>
        <span class="k">if</span> <span class="n">filled</span><span class="p">:</span>
            <span class="n">iso</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkBandedPolyDataContourFilter</span><span class="p">()</span>
            <span class="n">iso</span><span class="o">.</span><span class="n">SetScalarModeToValue</span><span class="p">()</span>
            <span class="c">#iso.SetScalarModeToIndex()</span>
            <span class="n">iso</span><span class="o">.</span><span class="n">GenerateContourEdgesOn</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">iso</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkContourFilter</span><span class="p">()</span>
        <span class="n">iso</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        
        <span class="n">cvector</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cvector&#39;</span><span class="p">)</span>
        <span class="n">clevels</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clevels&#39;</span><span class="p">)</span>  <span class="c"># number of contour levels</span>
        <span class="k">if</span> <span class="n">cvector</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># the contour levels are chosen automatically</span>
            <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">()</span>
            <span class="n">iso</span><span class="o">.</span><span class="n">SetNumberOfContours</span><span class="p">(</span><span class="n">clevels</span><span class="p">)</span>
            <span class="n">iso</span><span class="o">.</span><span class="n">GenerateValues</span><span class="p">(</span><span class="n">clevels</span><span class="p">,</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">clevels</span><span class="p">):</span>
                <span class="n">iso</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">cvector</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
        <span class="n">iso</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>

        <span class="n">isoMapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">isoMapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">iso</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="n">cmap</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_colormap</span>
        <span class="c">#if filled:</span>
        <span class="c">#    cmap.SetNumberOfColors(clevels)</span>
        <span class="c">#    cmap.Build()</span>
        <span class="n">isoMapper</span><span class="o">.</span><span class="n">SetLookupTable</span><span class="p">(</span><span class="n">cmap</span><span class="p">)</span>
        <span class="n">cax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_caxis</span>
        <span class="k">if</span> <span class="n">cax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">cax</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">()</span>
        <span class="n">isoMapper</span><span class="o">.</span><span class="n">SetScalarRange</span><span class="p">(</span><span class="n">cax</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linecolor&#39;</span><span class="p">):</span>  <span class="c"># linecolor is defined</span>
            <span class="n">isoMapper</span><span class="o">.</span><span class="n">ScalarVisibilityOff</span><span class="p">()</span>
        <span class="n">isoMapper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">isoActor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">isoActor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">isoMapper</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_actor_properties</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">isoActor</span><span class="p">)</span>
        <span class="c">#self._add_legend(item, iso.GetOutput())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">isoActor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>

        <span class="k">if</span> <span class="n">filled</span><span class="p">:</span>
            <span class="c"># create contour edges:</span>
            <span class="n">edgeMapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
            <span class="n">edgeMapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">iso</span><span class="o">.</span><span class="n">GetContourEdgesOutput</span><span class="p">())</span>
            <span class="n">edgeMapper</span><span class="o">.</span><span class="n">SetResolveCoincidentTopologyToPolygonOffset</span><span class="p">()</span>
            <span class="n">edgeActor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
            <span class="n">edgeActor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">edgeMapper</span><span class="p">)</span>
            <span class="n">fgcolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_color</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;fgcolor&#39;</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">))</span>
            <span class="n">edgecolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_color</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;edgecolor&#39;</span><span class="p">),</span> <span class="n">fgcolor</span><span class="p">)</span>
            <span class="n">edgeActor</span><span class="o">.</span><span class="n">GetProperty</span><span class="p">()</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="n">edgecolor</span><span class="p">)</span>
            <span class="c"># FIXME: use edgecolor property above (or black as default)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">edgeActor</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clabels&#39;</span><span class="p">):</span>
            <span class="c"># add labels on the contour curves</span>
            <span class="c"># subsample the points and label them:</span>
            <span class="n">mask</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkMaskPoints</span><span class="p">()</span>
            <span class="n">mask</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">iso</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="n">mask</span><span class="o">.</span><span class="n">SetOnRatio</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetNumberOfPoints</span><span class="p">()</span><span class="o">/</span><span class="mi">50</span><span class="p">))</span>
            <span class="n">mask</span><span class="o">.</span><span class="n">SetMaximumNumberOfPoints</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
            <span class="n">mask</span><span class="o">.</span><span class="n">RandomModeOn</span><span class="p">()</span>

            <span class="c"># Create labels for points - only show visible points</span>
            <span class="n">visPts</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkSelectVisiblePoints</span><span class="p">()</span>
            <span class="n">visPts</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">mask</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="n">visPts</span><span class="o">.</span><span class="n">SetRenderer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="p">)</span>
            <span class="n">ldm</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLabeledDataMapper</span><span class="p">()</span>
            <span class="n">ldm</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">mask</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="n">ldm</span><span class="o">.</span><span class="n">SetLabelFormat</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%.1g</span><span class="s">&quot;</span><span class="p">)</span>
            <span class="n">ldm</span><span class="o">.</span><span class="n">SetLabelModeToLabelScalars</span><span class="p">()</span>
            <span class="n">tprop</span> <span class="o">=</span> <span class="n">ldm</span><span class="o">.</span><span class="n">GetLabelTextProperty</span><span class="p">()</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetFontFamilyToArial</span><span class="p">()</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetFontSize</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">ShadowOff</span><span class="p">()</span>
            <span class="n">tprop</span><span class="o">.</span><span class="n">BoldOff</span><span class="p">()</span>
            <span class="n">contourLabels</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor2D</span><span class="p">()</span>
            <span class="n">contourLabels</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">ldm</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">contourLabels</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_add_vectors</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding vectors&quot;</span>
        <span class="c"># uncomment the following command if there is no support for</span>
        <span class="c"># automatic scaling of vectors in the current plotting package:</span>
        <span class="n">item</span><span class="o">.</span><span class="n">scale_vectors</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;udata&#39;</span><span class="p">))</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
            <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_3D_vector_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_2D_vector_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="c"># get line specifiactions (marker=&#39;.&#39; means no marker):</span>
        <span class="n">marker</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">style</span><span class="p">,</span> <span class="n">width</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_linespecs</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="c"># scale the vectors according to this variable (scale=0 should</span>
        <span class="c"># turn off automatic scaling):</span>
        <span class="n">scale</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;arrowscale&#39;</span><span class="p">)</span>

        <span class="n">filled</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;filledarrows&#39;</span><span class="p">)</span> <span class="c"># draw filled arrows if True</span>

        <span class="n">marker</span><span class="p">,</span> <span class="n">rotation</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_arrow_types</span><span class="p">[</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linemarker&#39;</span><span class="p">)]</span>
        <span class="n">arrow</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkGlyphSource2D</span><span class="p">()</span>
        <span class="n">arrow</span><span class="o">.</span><span class="n">SetGlyphType</span><span class="p">(</span><span class="n">marker</span><span class="p">)</span>
        <span class="n">arrow</span><span class="o">.</span><span class="n">SetFilled</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;filledarrows&#39;</span><span class="p">))</span>
        <span class="n">arrow</span><span class="o">.</span><span class="n">SetRotationAngle</span><span class="p">(</span><span class="n">rotation</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">arrow</span><span class="o">.</span><span class="n">GetGlyphType</span><span class="p">()</span> <span class="o">!=</span> <span class="mi">9</span><span class="p">:</span> <span class="c"># not an arrow</span>
            <span class="n">arrow</span><span class="o">.</span><span class="n">DashOn</span><span class="p">()</span>
            <span class="n">arrow</span><span class="o">.</span><span class="n">SetCenter</span><span class="p">(</span><span class="o">.</span><span class="mi">75</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">arrow</span><span class="o">.</span><span class="n">SetCenter</span><span class="p">(</span><span class="o">.</span><span class="mi">5</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>        
        <span class="n">arrow</span><span class="o">.</span><span class="n">SetColor</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_color</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;linecolor&#39;</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)))</span>

        <span class="n">plane</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGridGeometryFilter</span><span class="p">()</span>
        <span class="n">plane</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid</span><span class="p">)</span>
        <span class="n">plane</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cut_data</span><span class="p">(</span><span class="n">plane</span><span class="p">)</span>
        <span class="n">glyph</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkGlyph3D</span><span class="p">()</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span> 
        <span class="n">glyph</span><span class="o">.</span><span class="n">SetSource</span><span class="p">(</span><span class="n">arrow</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">SetColorModeToColorByVector</span><span class="p">()</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">SetRange</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">())</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">ScalingOn</span><span class="p">()</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">SetScaleModeToScaleByVector</span><span class="p">()</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">OrientOn</span><span class="p">()</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">SetVectorModeToUseVector</span><span class="p">()</span>
        <span class="n">glyph</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">glyph</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="c">#vr = data.GetOutput().GetPointData().GetVectors().GetRange()</span>
        <span class="c">#mapper.SetScalarRange(vr)</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">ScalarVisibilityOff</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_actor_properties</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
        <span class="c">#self._add_legend(item, arrow.GetOutput())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">glyph</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">_add_streams</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding streams&quot;</span>
            
        <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;udata&#39;</span><span class="p">))</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span> 
            <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_3D_vector_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_2D_vector_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="n">length</span> <span class="o">=</span> <span class="n">sgrid</span><span class="o">.</span><span class="n">GetLength</span><span class="p">()</span>
        <span class="n">max_velocity</span> <span class="o">=</span> <span class="n">sgrid</span><span class="o">.</span><span class="n">GetPointData</span><span class="p">()</span><span class="o">.</span><span class="n">GetVectors</span><span class="p">()</span><span class="o">.</span><span class="n">GetMaxNorm</span><span class="p">()</span>
        <span class="n">max_time</span> <span class="o">=</span> <span class="mf">35.0</span><span class="o">*</span><span class="n">length</span><span class="o">/</span><span class="n">max_velocity</span>
        
        <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>
        <span class="n">sx</span> <span class="o">=</span> <span class="n">ravel</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;startx&#39;</span><span class="p">))</span><span class="o">/</span><span class="n">dx</span>
        <span class="n">sy</span> <span class="o">=</span> <span class="n">ravel</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;starty&#39;</span><span class="p">))</span><span class="o">/</span><span class="n">dy</span>
        <span class="n">sz</span> <span class="o">=</span> <span class="n">ravel</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;startz&#39;</span><span class="p">))</span><span class="o">/</span><span class="n">dz</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofstreams&#39;</span><span class="p">)):</span>
            <span class="n">integ</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRungeKutta2</span><span class="p">()</span>
            <span class="c">#integ = vtk.vtkRungeKutta4()</span>
            <span class="n">stream</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStreamLine</span><span class="p">()</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid</span><span class="p">)</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">SetStepLength</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;stepsize&#39;</span><span class="p">))</span>
            <span class="c">#stream.SetIntegrationStepLength(item.getp(&#39;stepsize&#39;))</span>
            <span class="c">#stream.SetIntegrationDirectionToIntegrateBothDirections()</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">SetIntegrationDirectionToForward</span><span class="p">()</span>
            <span class="c">#stream.SetMaximumPropagationTime(max_time)</span>
            <span class="c">#stream.SetMaximumPropagationTime(200)</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">SpeedScalarsOn</span><span class="p">()</span>
            <span class="c">#stream.VorticityOn()</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">SetStartPosition</span><span class="p">(</span><span class="n">sx</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">sy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">sz</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">SetIntegrator</span><span class="p">(</span><span class="n">integ</span><span class="p">)</span>
            <span class="n">stream</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cut_data</span><span class="p">(</span><span class="n">stream</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;tubes&#39;</span><span class="p">):</span>
                <span class="c"># draw stream tubes:</span>
                <span class="n">ncirc</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;n&#39;</span><span class="p">)</span> 
                <span class="n">scale</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;tubescale&#39;</span><span class="p">)</span>
                <span class="n">streamtube</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTubeFilter</span><span class="p">()</span>
                <span class="n">streamtube</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
                <span class="n">streamtube</span><span class="o">.</span><span class="n">SetRadius</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
                <span class="n">streamtube</span><span class="o">.</span><span class="n">SetNumberOfSides</span><span class="p">(</span><span class="n">ncirc</span><span class="p">)</span>
                <span class="n">streamtube</span><span class="o">.</span><span class="n">SetVaryRadiusToVaryRadiusByVector</span><span class="p">()</span>
                <span class="n">streamtube</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
                <span class="n">output</span> <span class="o">=</span> <span class="n">streamtube</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ribbons&#39;</span><span class="p">):</span>
                <span class="c"># draw stream ribbons: </span>
                <span class="n">width</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ribbonwidth&#39;</span><span class="p">)</span>
                <span class="n">streamribbon</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRibbonFilter</span><span class="p">()</span>
                <span class="n">streamribbon</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
                <span class="n">streamribbon</span><span class="o">.</span><span class="n">VaryWidthOn</span><span class="p">()</span>
                <span class="n">streamribbon</span><span class="o">.</span><span class="n">SetWidthFactor</span><span class="p">(</span><span class="n">width</span><span class="p">)</span>
                <span class="c">#streamribbon.SetAngle(90)</span>
                <span class="n">streamribbon</span><span class="o">.</span><span class="n">SetDefaultNormal</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">streamribbon</span><span class="o">.</span><span class="n">UseDefaultNormalOn</span><span class="p">()</span>
                <span class="n">streamribbon</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
                <span class="n">output</span> <span class="o">=</span> <span class="n">streamribbon</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># draw stream lines:</span>
                <span class="n">output</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span>

            <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetLookupTable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_colormap</span><span class="p">)</span>
            <span class="n">cax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_caxis</span>
            <span class="k">if</span> <span class="n">cax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">cax</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">GetBounds</span><span class="p">()[</span><span class="mi">4</span><span class="p">:]</span>
                <span class="c">#cax = sgrid.GetScalarRange()</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetScalarRange</span><span class="p">(</span><span class="n">cax</span><span class="p">)</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
            <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
            <span class="c">#self._set_shading(item, stream, actor)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_actor_properties</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
            <span class="c">#self._add_legend(item, output)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_add_isosurface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding a isosurface&quot;</span>
        <span class="c"># grid components:</span>
        <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">z</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;xdata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;ydata&#39;</span><span class="p">),</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;zdata&#39;</span><span class="p">)</span>
        <span class="n">v</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;vdata&#39;</span><span class="p">)</span>  <span class="c"># volume</span>
        <span class="n">c</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cdata&#39;</span><span class="p">)</span>  <span class="c"># pseudocolor data</span>
        <span class="n">isovalue</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;isovalue&#39;</span><span class="p">)</span>

        <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_3D_scalar_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
        <span class="n">iso</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkContourFilter</span><span class="p">()</span>
        <span class="n">iso</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid</span><span class="p">)</span>
        <span class="n">iso</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">isovalue</span><span class="p">)</span>
        <span class="n">iso</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cut_data</span><span class="p">(</span><span class="n">iso</span><span class="p">)</span>
        <span class="n">normals</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataNormals</span><span class="p">()</span>
        <span class="n">normals</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="n">normals</span><span class="o">.</span><span class="n">SetFeatureAngle</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
        <span class="n">normals</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">normals</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetLookupTable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_colormap</span><span class="p">)</span>
        <span class="n">cax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_caxis</span>
        <span class="k">if</span> <span class="n">cax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">cax</span> <span class="o">=</span> <span class="n">sgrid</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">()</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">SetScalarRange</span><span class="p">(</span><span class="n">cax</span><span class="p">)</span>
        <span class="n">mapper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
        <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
        <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_shading</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_actor_properties</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">normals</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">_add_slices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">,</span> <span class="n">contours</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding slices in a volume&quot;</span>

        <span class="n">sgrid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_3D_scalar_data</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>

        <span class="n">sx</span><span class="p">,</span> <span class="n">sy</span><span class="p">,</span> <span class="n">sz</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;slices&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">rank</span><span class="p">(</span><span class="n">sz</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="c"># sx, sy, and sz defines a surface</span>
            <span class="n">h</span> <span class="o">=</span> <span class="n">Surface</span><span class="p">(</span><span class="n">sx</span><span class="p">,</span><span class="n">sy</span><span class="p">,</span><span class="n">sz</span><span class="p">)</span>
            <span class="n">sgrid2</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_create_2D_scalar_data</span><span class="p">(</span><span class="n">h</span><span class="p">)</span>
            <span class="n">plane</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkStructuredGridGeometryFilter</span><span class="p">()</span>
            <span class="n">plane</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid2</span><span class="p">)</span>
            <span class="n">plane</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
            <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cut_data</span><span class="p">(</span><span class="n">plane</span><span class="p">)</span>
            <span class="n">implds</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkImplicitDataSet</span><span class="p">()</span>
            <span class="n">implds</span><span class="o">.</span><span class="n">SetDataSet</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="n">implds</span><span class="o">.</span><span class="n">Modified</span><span class="p">()</span>
            <span class="n">cut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCutter</span><span class="p">()</span>
            <span class="n">cut</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid</span><span class="p">)</span>
            <span class="n">cut</span><span class="o">.</span><span class="n">SetCutFunction</span><span class="p">(</span><span class="n">implds</span><span class="p">)</span>
            <span class="n">cut</span><span class="o">.</span><span class="n">GenerateValues</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
            <span class="n">cut</span><span class="o">.</span><span class="n">GenerateCutScalarsOn</span><span class="p">()</span>
            <span class="n">cut</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
            <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">cut</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetLookupTable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_colormap</span><span class="p">)</span>
            <span class="n">cax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_caxis</span>
            <span class="k">if</span> <span class="n">cax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="n">cax</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">()</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">SetScalarRange</span><span class="p">(</span><span class="n">cax</span><span class="p">)</span>
            <span class="n">mapper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
            <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
            <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_shading</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_set_actor_properties</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">cut</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># sx, sy, and sz is either numbers or vectors with numbers</span>
            <span class="n">origins</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">normals</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="n">center</span> <span class="o">=</span> <span class="n">sgrid</span><span class="o">.</span><span class="n">GetCenter</span><span class="p">()</span>
            <span class="n">dx</span><span class="p">,</span> <span class="n">dy</span><span class="p">,</span> <span class="n">dz</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;daspect&#39;</span><span class="p">)</span>
            <span class="n">sx</span> <span class="o">=</span> <span class="n">ravel</span><span class="p">(</span><span class="n">sx</span><span class="p">)</span><span class="o">/</span><span class="n">dx</span>
            <span class="n">sy</span> <span class="o">=</span> <span class="n">ravel</span><span class="p">(</span><span class="n">sy</span><span class="p">)</span><span class="o">/</span><span class="n">dy</span>
            <span class="n">sz</span> <span class="o">=</span> <span class="n">ravel</span><span class="p">(</span><span class="n">sz</span><span class="p">)</span><span class="o">/</span><span class="n">dz</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sx</span><span class="p">)):</span>
                <span class="n">normals</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">origins</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">sx</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sy</span><span class="p">)):</span>
                <span class="n">normals</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">])</span>
                <span class="n">origins</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">sy</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">sz</span><span class="p">)):</span>
                <span class="n">normals</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">])</span>
                <span class="n">origins</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">center</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">center</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">sz</span><span class="p">[</span><span class="n">i</span><span class="p">]])</span>
            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">normals</span><span class="p">)):</span>
                <span class="n">plane</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPlane</span><span class="p">()</span>
                <span class="n">plane</span><span class="o">.</span><span class="n">SetOrigin</span><span class="p">(</span><span class="n">origins</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="n">plane</span><span class="o">.</span><span class="n">SetNormal</span><span class="p">(</span><span class="n">normals</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                <span class="n">cut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkCutter</span><span class="p">()</span>
                <span class="n">cut</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">sgrid</span><span class="p">)</span>
                <span class="n">cut</span><span class="o">.</span><span class="n">SetCutFunction</span><span class="p">(</span><span class="n">plane</span><span class="p">)</span>
                <span class="n">cut</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
                <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cut_data</span><span class="p">(</span><span class="n">cut</span><span class="p">)</span>
                <span class="n">mapper</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPolyDataMapper</span><span class="p">()</span>
                <span class="k">if</span> <span class="n">contours</span><span class="p">:</span>
                    <span class="n">iso</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkContourFilter</span><span class="p">()</span>
                    <span class="n">iso</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
                    <span class="n">cvector</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;cvector&#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">cvector</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">cvector</span><span class="p">)):</span>
                            <span class="n">iso</span><span class="o">.</span><span class="n">SetValue</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">cvector</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">()</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">()</span>
                        <span class="n">iso</span><span class="o">.</span><span class="n">GenerateValues</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;clevels&#39;</span><span class="p">),</span> <span class="n">zmin</span><span class="p">,</span> <span class="n">zmax</span><span class="p">)</span>
                    <span class="n">iso</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
                    <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">iso</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">mapper</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>
                <span class="n">mapper</span><span class="o">.</span><span class="n">SetLookupTable</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_colormap</span><span class="p">)</span>
                <span class="n">cax</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_caxis</span>
                <span class="k">if</span> <span class="n">cax</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                    <span class="n">cax</span> <span class="o">=</span> <span class="n">sgrid</span><span class="o">.</span><span class="n">GetScalarRange</span><span class="p">()</span>
                <span class="n">mapper</span><span class="o">.</span><span class="n">SetScalarRange</span><span class="p">(</span><span class="n">cax</span><span class="p">)</span>
                <span class="n">mapper</span><span class="o">.</span><span class="n">Update</span><span class="p">()</span>
                <span class="n">actor</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkActor</span><span class="p">()</span>
                <span class="n">actor</span><span class="o">.</span><span class="n">SetMapper</span><span class="p">(</span><span class="n">mapper</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">contours</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_set_shading</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_set_actor_properties</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">actor</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">AddActor</span><span class="p">(</span><span class="n">actor</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span><span class="o">.</span><span class="n">_apd</span><span class="o">.</span><span class="n">AddInput</span><span class="p">(</span><span class="n">cut</span><span class="o">.</span><span class="n">GetOutput</span><span class="p">())</span>

    <span class="k">def</span> <span class="nf">_add_contourslices</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">item</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Adding contours in slice planes&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_add_slices</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">contours</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_set_figure_size</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fig</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Setting figure size&quot;</span>
        <span class="n">width</span><span class="p">,</span> <span class="n">height</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;size&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">width</span> <span class="ow">and</span> <span class="n">height</span><span class="p">:</span>
            <span class="c"># set figure width and height</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">set_size</span><span class="p">(</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># use the default width and height in plotting package</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">set_size</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">600</span><span class="p">)</span>
            <span class="k">pass</span>

<div class="viewcode-block" id="VTKBackend.figure"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.figure">[docs]</a>    <span class="k">def</span> <span class="nf">figure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="c"># Extension of BaseClass.figure:</span>
        <span class="c"># add a plotting package figure instance as fig._g and create a</span>
        <span class="c"># link to it as self._g</span>
        <span class="n">fig</span> <span class="o">=</span> <span class="n">BaseClass</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">fig</span><span class="o">.</span><span class="n">_g</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="c"># create plotting package figure and save figure instance</span>
            <span class="c"># as fig._g</span>
            <span class="n">name</span> <span class="o">=</span> <span class="s">&#39;Figure &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;number&#39;</span><span class="p">))</span>
            <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;creating figure </span><span class="si">%s</span><span class="s"> in backend&quot;</span> <span class="o">%</span> <span class="n">name</span>

            <span class="n">fig</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="n">_VTKFigure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
            
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">_g</span>  <span class="c"># link for faster access</span>
        <span class="k">return</span> <span class="n">fig</span>
</div>
    <span class="k">def</span> <span class="nf">_setup_axis</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ax</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_limits</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_daspect</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_colormap</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_caxis</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>

        <span class="c"># Create a renderer for this axis and add it to the current</span>
        <span class="c"># figures renderer window:</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">_renderer</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkRenderer</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">AddRenderer</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">_renderer</span><span class="p">)</span>
        
        <span class="c"># Set the renderers background color:</span>
        <span class="n">bgcolor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_colors</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;bgcolor&#39;</span><span class="p">),</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">))</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">SetBackground</span><span class="p">(</span><span class="n">bgcolor</span><span class="p">)</span>
        
        <span class="n">rect</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;viewport&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">rect</span><span class="p">:</span>
            <span class="n">rect</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">SetViewport</span><span class="p">(</span><span class="n">rect</span><span class="p">)</span>
        
        <span class="n">ax</span><span class="o">.</span><span class="n">_renderer</span><span class="o">.</span><span class="n">RemoveAllViewProps</span><span class="p">()</span>  <span class="c"># clear current scene</span>
        <span class="c">#axshape = self.gcf().getp(&#39;axshape&#39;)</span>
        <span class="c">#ax._renderer.SetPixelAspect(axshape[1], axshape[0])</span>

        <span class="n">ax</span><span class="o">.</span><span class="n">_apd</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkAppendPolyData</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">_fix_latex</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">legend</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Remove latex syntax a la $, \, {, } etc.&quot;&quot;&quot;</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
        <span class="c"># General fix of latex syntax (more readable)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;**&#39;</span><span class="p">,</span> <span class="s">&#39;^&#39;</span><span class="p">)</span>  
        <span class="c">#legend = legend.replace(&#39;*&#39;, &#39;&#39;)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;$&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;{&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;}&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="n">legend</span> <span class="o">=</span> <span class="n">legend</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\\</span><span class="s">&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">legend</span>

    <span class="k">def</span> <span class="nf">_replot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Replot all axes and all plotitems in the backend.&quot;&quot;&quot;</span>
        <span class="c"># NOTE: only the current figure (gcf) is redrawn.</span>
        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Doing replot in backend&quot;</span>
        
        <span class="n">fig</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gcf</span><span class="p">()</span>
        <span class="c"># reset the plotting package instance in fig._g now if needed</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">_set_figure_size</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
        
        <span class="n">nrows</span><span class="p">,</span> <span class="n">ncolumns</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;axshape&#39;</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">axnr</span><span class="p">,</span> <span class="n">ax</span> <span class="ow">in</span> <span class="n">fig</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;axes&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;numberofitems&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="k">continue</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_ax</span> <span class="o">=</span> <span class="n">ax</span>  <span class="c"># link for faster access</span>
            <span class="k">if</span> <span class="n">nrows</span> <span class="o">!=</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">ncolumns</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                <span class="c"># create axes in tiled position</span>
                <span class="c"># this is subplot(nrows,ncolumns,axnr)</span>
                <span class="k">pass</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_setup_axis</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
            <span class="n">plotitems</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;plotitems&#39;</span><span class="p">)</span>
            <span class="n">plotitems</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cmpPlotProperties</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">plotitems</span><span class="p">:</span>
                <span class="n">func</span> <span class="o">=</span> <span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;function&#39;</span><span class="p">)</span> <span class="c"># function that produced this item</span>
                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Line</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_add_line</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Surface</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_add_surface</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">shading</span><span class="o">=</span><span class="n">ax</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;shading&#39;</span><span class="p">))</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Contours</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_add_contours</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">VelocityVectors</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_add_vectors</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Streams</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_add_streams</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">Volume</span><span class="p">):</span>
                    <span class="k">if</span> <span class="n">func</span> <span class="o">==</span> <span class="s">&#39;isosurface&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_add_isosurface</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">func</span> <span class="o">==</span> <span class="s">&#39;slice_&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_add_slices</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                    <span class="k">elif</span> <span class="n">func</span> <span class="o">==</span> <span class="s">&#39;contourslice&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_add_contourslices</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
                <span class="n">legend</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fix_latex</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;legend&#39;</span><span class="p">))</span>
                <span class="k">if</span> <span class="n">legend</span><span class="p">:</span>
                    <span class="c"># add legend to plot</span>
                    <span class="k">pass</span>

            <span class="bp">self</span><span class="o">.</span><span class="n">_set_axis_props</span><span class="p">(</span><span class="n">ax</span><span class="p">)</span>
                    
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;show&#39;</span><span class="p">):</span>
            <span class="c"># display plot on the screen</span>
            <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
                <span class="k">print</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">Dumping plot data to screen</span><span class="se">\n</span><span class="s">&quot;</span>
                <span class="n">debug</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
            <span class="k">pass</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">display</span><span class="p">(</span><span class="n">show</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;show&#39;</span><span class="p">))</span>

<div class="viewcode-block" id="VTKBackend.hardcopy"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.hardcopy">[docs]</a>    <span class="k">def</span> <span class="nf">hardcopy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Supported extensions in VTK backend:</span>

<span class="sd">          &#39;.ps&#39;  (PostScript)</span>
<span class="sd">          &#39;.eps&#39; (Encapsualted PostScript)</span>
<span class="sd">          &#39;.pdf&#39; (Portable Document Format)</span>
<span class="sd">          &#39;.jpg&#39; (Joint Photographic Experts Group)</span>
<span class="sd">          &#39;.png&#39; (Portable Network Graphics)</span>
<span class="sd">          &#39;.pnm&#39; (Portable Any Map)</span>
<span class="sd">          &#39;.tif&#39; (Tagged Image File Format)</span>
<span class="sd">          &#39;.bmp&#39; (Bitmap Image)</span>

<span class="sd">        Optional arguments for JPEG output:</span>

<span class="sd">          quality     -- Set the quality of the resulting JPEG image. The</span>
<span class="sd">                         argument must be given as an integer between 0 and</span>
<span class="sd">                         100, where 100 gives the best quality (but also</span>
<span class="sd">                         the largest file). Default quality is 100.</span>

<span class="sd">          progressive -- Set whether to use progressive JPEG generation or</span>
<span class="sd">                         not. Default is False.</span>

<span class="sd">        Optional arguments for PostScript and PDF output:</span>

<span class="sd">          vector_file -- If True (default), the figure will be stored as a</span>
<span class="sd">                         vector file, i.e., using vtkGL2PSExporter instead</span>
<span class="sd">                         of vtkPostScriptWriter (requires VTK to be built</span>
<span class="sd">                         with GL2PS support). GL2PS gives much better</span>
<span class="sd">                         results, but at a cost of longer generation times</span>
<span class="sd">                         and larger files.</span>
<span class="sd">                         </span>
<span class="sd">          orientation -- Set the orientation to either &#39;portrait&#39; (default)</span>
<span class="sd">                         or &#39;landscape&#39;. This option only has effect when</span>
<span class="sd">                         vector_file is True.</span>
<span class="sd">                         </span>
<span class="sd">          raster3d    -- If True, this will write 3D props as raster images</span>
<span class="sd">                         while 2D props are rendered using vector graphic</span>
<span class="sd">                         primitives. Default is False. This option only has</span>
<span class="sd">                         effect when vector_file is True.</span>
<span class="sd">                         </span>
<span class="sd">          compression -- If True, compression will be used when generating</span>
<span class="sd">                         PostScript or PDF output. Default is False (no</span>
<span class="sd">                         compression). This option only has effect when</span>
<span class="sd">                         vector_file is True.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;color&#39;</span><span class="p">)</span>
        <span class="n">replot</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;replot&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
        
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">getp</span><span class="p">(</span><span class="s">&#39;show&#39;</span><span class="p">):</span>  <span class="c"># don&#39;t render to screen</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">OffScreenRenderingOn</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">replot</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_replot</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">DEBUG</span><span class="p">:</span>
            <span class="k">print</span> <span class="s">&quot;Hardcopy to </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">filename</span>

        <span class="n">basename</span><span class="p">,</span> <span class="n">ext</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">ext</span><span class="p">:</span>
            <span class="c"># no extension given, assume .ps:</span>
            <span class="n">ext</span> <span class="o">=</span> <span class="s">&#39;.ps&#39;</span>
            <span class="n">filename</span> <span class="o">+=</span> <span class="n">ext</span>

        <span class="n">jpeg_quality</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;quality&#39;</span><span class="p">,</span> <span class="mi">100</span><span class="p">))</span>
        <span class="n">progressive</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;progressive&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">))</span>
        <span class="n">vector_file</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;vector_file&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">))</span>
        <span class="n">orientation</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;orientation&#39;</span><span class="p">,</span> <span class="s">&#39;portrait&#39;</span><span class="p">)</span>
        <span class="n">raster3d</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;raster3d&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">))</span>
        <span class="n">compression</span> <span class="o">=</span> <span class="nb">bool</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;compression&#39;</span><span class="p">,</span> <span class="bp">False</span><span class="p">))</span>
        
        <span class="n">landscape</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="n">orientation</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;landscape&#39;</span><span class="p">:</span>
            <span class="n">landscape</span> <span class="o">=</span> <span class="bp">True</span>
            
        <span class="n">vector_file_formats</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;.ps&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span> <span class="s">&#39;.eps&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s">&#39;.pdf&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span> <span class="s">&#39;.tex&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">vector_file</span> <span class="ow">and</span> <span class="n">ext</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="n">vector_file_formats</span><span class="p">:</span>
            <span class="n">exp</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkGL2PSExporter</span><span class="p">()</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">SetRenderWindow</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">renwin</span><span class="p">)</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">SetFilePrefix</span><span class="p">(</span><span class="n">basename</span><span class="p">)</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">SetFileFormat</span><span class="p">(</span><span class="n">vector_file_formats</span><span class="p">[</span><span class="n">ext</span><span class="o">.</span><span class="n">lower</span><span class="p">()])</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">SetCompress</span><span class="p">(</span><span class="n">compression</span><span class="p">)</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">SetLandscape</span><span class="p">(</span><span class="n">landscape</span><span class="p">)</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">SetSortToBSP</span><span class="p">()</span>
            <span class="c">#exp.SetSortToSimple()  # less expensive sort algorithm</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">DrawBackgroundOn</span><span class="p">()</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">SetWrite3DPropsAsRasterImage</span><span class="p">(</span><span class="n">raster3d</span><span class="p">)</span>
            <span class="n">exp</span><span class="o">.</span><span class="n">Write</span><span class="p">()</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">vtk_image_writers</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s">&#39;.tif&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTIFFWriter</span><span class="p">(),</span>
                <span class="s">&#39;.tiff&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkTIFFWriter</span><span class="p">(),</span>
                <span class="s">&#39;.bmp&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkBMPWriter</span><span class="p">(),</span>
                <span class="s">&#39;.pnm&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPNMWriter</span><span class="p">(),</span>
                <span class="s">&#39;.png&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPNGWriter</span><span class="p">(),</span>
                <span class="s">&#39;.jpg&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkJPEGWriter</span><span class="p">(),</span>
                <span class="s">&#39;.jpeg&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkJPEGWriter</span><span class="p">(),</span>
                <span class="s">&#39;.ps&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPostScriptWriter</span><span class="p">(),</span>
                <span class="s">&#39;.eps&#39;</span><span class="p">:</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkPostScriptWriter</span><span class="p">(),</span>  <span class="c"># gives a normal PS file</span>
                <span class="p">}</span>
            <span class="n">w2if</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkWindowToImageFilter</span><span class="p">()</span>
            <span class="n">w2if</span><span class="o">.</span><span class="n">SetInput</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">renwin</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">writer</span> <span class="o">=</span> <span class="n">vtk_image_writers</span><span class="p">[</span><span class="n">ext</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                    <span class="s">&quot;hardcopy: Extension &#39;</span><span class="si">%s</span><span class="s">&#39; is currently not supported.&quot;</span> \
                    <span class="o">%</span> <span class="n">ext</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">ext</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&#39;.jpg&#39;</span><span class="p">,</span> <span class="s">&#39;.jpeg&#39;</span><span class="p">):</span>
                <span class="n">writer</span><span class="o">.</span><span class="n">SetQuality</span><span class="p">(</span><span class="n">jpeg_quality</span><span class="p">)</span>
                <span class="n">writer</span><span class="o">.</span><span class="n">SetProgressive</span><span class="p">(</span><span class="n">progressive</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">ext</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&#39;.tif&#39;</span><span class="p">,</span> <span class="s">&#39;.tiff&#39;</span><span class="p">):</span>
                <span class="c"># FIXME: allow to set compression mode for TIFF output</span>
                <span class="c"># see http://www.vtk.org/doc/release/5.0/html/a02108.html</span>
                <span class="k">pass</span>
            <span class="n">writer</span><span class="o">.</span><span class="n">SetFileName</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
            <span class="n">writer</span><span class="o">.</span><span class="n">SetInputConnection</span><span class="p">(</span><span class="n">w2if</span><span class="o">.</span><span class="n">GetOutputPort</span><span class="p">())</span>
            <span class="n">writer</span><span class="o">.</span><span class="n">Write</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_g</span><span class="o">.</span><span class="n">renwin</span><span class="o">.</span><span class="n">OffScreenRenderingOff</span><span class="p">()</span>


    <span class="c"># reimplement color maps and other methods (if necessary) like clf,</span>
    <span class="c"># closefig, and closefigs here.</span>
</div>
<div class="viewcode-block" id="VTKBackend.hsv"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.hsv">[docs]</a>    <span class="k">def</span> <span class="nf">hsv</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetHueRange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetSaturationRange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetValueRange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.gray"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.gray">[docs]</a>    <span class="k">def</span> <span class="nf">gray</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetHueRange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetSaturationRange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetValueRange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.hot"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.hot">[docs]</a>    <span class="k">def</span> <span class="nf">hot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">inc</span> <span class="o">=</span> <span class="mf">0.01175</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="mi">256</span><span class="p">)</span>
        <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">r</span> <span class="o">=</span> <span class="mf">0.0</span><span class="p">;</span> <span class="n">g</span> <span class="o">=</span> <span class="mf">0.0</span><span class="p">;</span> <span class="n">b</span> <span class="o">=</span> <span class="mf">0.0</span>
        <span class="k">while</span> <span class="n">r</span> <span class="o">&lt;=</span> <span class="mf">1.</span><span class="p">:</span>
            <span class="n">lut</span><span class="o">.</span><span class="n">SetTableValue</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">r</span> <span class="o">+=</span> <span class="n">inc</span><span class="p">;</span>  <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">r</span> <span class="o">=</span> <span class="mf">1.</span>
        <span class="k">while</span> <span class="n">g</span> <span class="o">&lt;=</span> <span class="mf">1.</span><span class="p">:</span>
            <span class="n">lut</span><span class="o">.</span><span class="n">SetTableValue</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">g</span> <span class="o">+=</span> <span class="n">inc</span><span class="p">;</span>  <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">g</span> <span class="o">=</span> <span class="mf">1.</span>
        <span class="k">while</span> <span class="n">b</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">i</span> <span class="o">==</span> <span class="mi">256</span><span class="p">:</span> <span class="k">break</span>
            <span class="n">lut</span><span class="o">.</span><span class="n">SetTableValue</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
            <span class="n">b</span> <span class="o">+=</span> <span class="n">inc</span><span class="p">;</span>  <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.flag"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.flag">[docs]</a>    <span class="k">def</span> <span class="nf">flag</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="k">assert</span> <span class="n">m</span><span class="o">%</span><span class="mi">4</span><span class="o">==</span><span class="mi">0</span><span class="p">,</span> <span class="s">&quot;flag: the number of colors must be a multiple of 4.&quot;</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="c"># the last parameter alpha is set to 1 by default</span>
        <span class="c"># in method declaration</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">m</span><span class="p">,</span><span class="mi">4</span><span class="p">):</span>
            <span class="n">lut</span><span class="o">.</span><span class="n">SetTableValue</span><span class="p">(</span><span class="n">i</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>   <span class="c"># red</span>
            <span class="n">lut</span><span class="o">.</span><span class="n">SetTableValue</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">i</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="c"># white</span>
            <span class="n">lut</span><span class="o">.</span><span class="n">SetTableValue</span><span class="p">(</span><span class="mi">2</span><span class="o">+</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="c"># blue</span>
            <span class="n">lut</span><span class="o">.</span><span class="n">SetTableValue</span><span class="p">(</span><span class="mi">3</span><span class="o">+</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="c"># black</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.jet"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.jet">[docs]</a>    <span class="k">def</span> <span class="nf">jet</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="c"># blue, cyan, green, yellow, red, black</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetHueRange</span><span class="p">(</span><span class="mf">0.667</span><span class="p">,</span><span class="mf">0.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.spring"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.spring">[docs]</a>    <span class="k">def</span> <span class="nf">spring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetHueRange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.17</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetSaturationRange</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span> 
        <span class="n">lut</span><span class="o">.</span><span class="n">SetValueRange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.summer"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.summer">[docs]</a>    <span class="k">def</span> <span class="nf">summer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetHueRange</span><span class="p">(</span><span class="mf">0.47</span><span class="p">,</span> <span class="mf">0.17</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetSaturationRange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.6</span><span class="p">)</span> 
        <span class="n">lut</span><span class="o">.</span><span class="n">SetValueRange</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.winter"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.winter">[docs]</a>    <span class="k">def</span> <span class="nf">winter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetHueRange</span><span class="p">(</span><span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.42</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetSaturationRange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span> 
        <span class="n">lut</span><span class="o">.</span><span class="n">SetValueRange</span><span class="p">(</span><span class="mf">0.6</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>
</div>
<div class="viewcode-block" id="VTKBackend.autumn"><a class="viewcode-back" href="../../../vtk_new_.html#scitools.easyviz.vtk_new_.VTKBackend.autumn">[docs]</a>    <span class="k">def</span> <span class="nf">autumn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="o">=</span><span class="mi">64</span><span class="p">):</span>
        <span class="n">lut</span> <span class="o">=</span> <span class="n">vtk</span><span class="o">.</span><span class="n">vtkLookupTable</span><span class="p">()</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetNumberOfColors</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetHueRange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.15</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">SetSaturationRange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span> 
        <span class="n">lut</span><span class="o">.</span><span class="n">SetValueRange</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
        <span class="n">lut</span><span class="o">.</span><span class="n">Build</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">lut</span>

    <span class="c"># Now we add the doc string from the methods in BaseClass to the</span>
    <span class="c"># methods that are reimplemented in this backend:</span></div>
    <span class="k">for</span> <span class="n">cmd</span> <span class="ow">in</span> <span class="n">BaseClass</span><span class="o">.</span><span class="n">_matlab_like_cmds</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="s">&#39;__&#39;</span> <span class="ow">in</span> <span class="n">cmd</span> <span class="ow">and</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">BaseClass</span><span class="p">,</span> <span class="n">cmd</span><span class="p">):</span>
            <span class="n">m1</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="s">&#39;BaseClass.</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">cmd</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">m2</span> <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">cmd</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">NameError</span><span class="p">:</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">m1</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">!=</span> <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                        <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
                    <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">=</span> <span class="n">m1</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">+</span> <span class="n">m2</span><span class="o">.</span><span class="n">__doc__</span>

</div>
<span class="n">plt</span> <span class="o">=</span> <span class="n">VTKBackend</span><span class="p">()</span>   <span class="c"># create backend instance</span>
<span class="n">use</span><span class="p">(</span><span class="n">plt</span><span class="p">,</span> <span class="nb">globals</span><span class="p">())</span>  <span class="c"># export public namespace of plt to globals()</span>
<span class="n">backend</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">__file__</span><span class="p">))[</span><span class="mi">0</span><span class="p">][:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/scitools_logo.jpg" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, H. P. Langtangen, J. Ring, ++.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
    </div>
  </body>
</html>